﻿using System;
using System.Collections.ObjectModel;

namespace Unknown.Framework.Develop
{
    /// <summary>
    /// 转储数据类
    /// </summary>
    public class Dump
    {
        /// <summary>
        /// 时间
        /// </summary>
        public DateTime Time { get; set; }
        /// <summary>
        /// 命名空间
        /// </summary>
        public string Namespace { get; set; }
        /// <summary>
        /// 类
        /// </summary>
        public string Class { get; set; }
        /// <summary>
        /// 方法
        /// </summary>
        public string Method { get; set; }
        /// <summary>
        /// 位置
        /// </summary>
        public string Position { get; set; }
        /// <summary>
        /// 消息
        /// </summary>
        public string Message { get; set; }

        private Collection<string> _Remarks = new Collection<string>();
        /// <summary>
        /// 备注
        /// </summary>
        public Collection<string> Remarks
        {
            get
            {
                return this._Remarks;
            }
        }

        /// <summary>
        /// 构造函数
        /// </summary>
        public Dump()
        {
        }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="exception">异常</param>
        /// <param name="remarks">备注</param>
        public Dump(Exception exception, Collection<string> remarks)
        {
            this.Time = DateTime.Now;

            if (exception != null)
            {
                if (exception.TargetSite != null)
                {
                    Type type = exception.TargetSite.DeclaringType;

                    this.Namespace = type.Namespace;
                    this.Class = type.Name;
                    this.Method = exception.TargetSite.Name;
                }
                this.Position = exception.StackTrace;
                this.Message = exception.Message;
            }

            if (remarks != null)
            {
                this._Remarks = remarks;
            }
        }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="exception">异常</param>
        public Dump(Exception exception)
            : this(exception, null)
        {
        }
    }
}